import request from "@/utils";
import type { ResType } from "./shared";

export type ChannelItem = {
  id: number;
  name: string;
};
type ChannelRes = {
  channels: ChannelItem[];
};

// 请求频道列表
export const getChannelListApi = () =>
  request.request<ResType<ChannelRes>>({
    url: "/channels",
  });

export type BookItem = {
  art_id: string;
  aut_id: string;
  aut_name: string;
  comm_count: number;
  cover: {
    type: number;
    images: string[];
  };
  is_top: number;
  pubdate: number;
  title: number;
};

export type BookRes = {
  results: BookItem[];
  pre_timestamp: string;
};

interface ParamsType {
  channel_id: string;
  timestamp: string;
}

// 请求文章列表
export const getBookListApi = (params: ParamsType) =>
  request.request<ResType<BookRes>>({
    url: "/articles",
    params,
  });

/**
 * 响应数据
 */
export type DetailDataType = {
  art_id: string; // 文章id

  attitude: number; // 文章-是否被点赞，-1无态度, 0未点赞, 1点赞, 是当前登录用户对此文章的态度

  aut_id: string; // 文章作者id

  aut_name: string; // 文章作者名

  aut_photo: string; // 文章作者头像，无头像, 默认为null

  comm_count: number; // 文章_评论总数

  content: string; // 文章内容

  is_collected: boolean; // 文章-是否被收藏，true(已收藏)false(未收藏)是登录的用户对此文章的收藏状态

  is_followed: boolean; // 文章作者-是否被关注，true(关注)false(未关注), 说的是当前登录用户对这个文章作者的关注状态

  like_count: number; //文章_点赞总数

  pubdate: string; // 文章发布时间

  read_count: number; // 文章_阅读总数

  title: string; // 文章标题
};

export function getDetailAPI(id: string) {
  return request.request<ResType<DetailDataType>>({
    url: `/articles/${id}`,
  });
}
